package com.lancoo.znbkxx.teacher.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.util.Log;

import androidx.core.content.FileProvider;

import java.io.File;

/**
 * Created by Dadong on 2020/4/10
 * Describe:
 */
public class ExportUtil {


    public static void shareFile(Activity activity, String shareFileLocalPath, Context context) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        //判断是否大于安卓7.0
        Uri uri = isSeven(context, new File(shareFileLocalPath), intent);
        Log.e("==uri地址5==", "===========uri===========" + uri);
        intent.setType("*/*");
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        activity.startActivity(Intent.createChooser(intent, "分享"));
    }

    //判断是否大于安卓7.0
    private static Uri isSeven(Context context, File file, Intent intent) {
        Uri uri = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            //大于7.0，应使用该路径
            uri = FileProvider.getUriForFile(context, "com.lancoo.znbkxx.teacher.fileprovider", file);
            // 给目标应用一个临时授权
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Log.e("isSeven", "====================0000000000000000====");
        } else {
            //小于7.0
            uri = Uri.fromFile(file);
            Log.e("isSeven", "====================1111111111111111====");
        }
        return uri;
    }
}
